#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=100010; 
int main()
{
	int n,m,a[maxn];
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	} 
	int i=0,j=0,sum=0,ans=maxn;
	while(1){
		while(j<n&&sum<m){
			if(a[j]>0)
				sum+=a[j];
			j++;
		}
		ans=min(ans,abs(m-sum));
		if(sum<m&&sum>0) break;
		sum-=a[i++];
	}
	printf("%d",ans);
	return 0;
}

